Create feature definitions from .csv template
Creating the new feature definition by reading values from .csv file. It creates a new feature definition in point category and in alignment category.
The below image shows the content of .csv file used, The first column defines the feature definition name to set, and second column defines the category for adding the new feature definition.
//Required References
using System;
using System.IO;
public void CreateFeatureDefinitions()
{
//.CSV file name to read data for creating feature definitions
string fileName = "D:\\DrawingProduction\\FeatureDefinitionTemplate.csv";
//Read all lines from csv file into array of strings
String[] lines = File.ReadAllLines(fileName);
//Get Object space required for persisting the changes
Bentley.CifNET.CadSystem.IObjectSpaceManager objectSpaceManager = Bentley.CifNET.ServiceManager.Instance.GetService<Bentley.CifNET.CadSystem.IObjectSpaceManager>();
Bentley.CifNET.Objects.IObjectSpace objectSpace = objectSpaceManager.ObjectSpace;
if (objectSpace == null) return;
//Get or create ContentManagementModel
Bentley.CifNET.ContentManagementModel.ContentManagementModel cmm = Bentley.CifNET.ContentManagementModel.ContentManagementModel.GetContentManagementModelAndCreateIfDontExist(objectSpace);
if (cmm == null) return;
for (int itr = 1; itr < lines.Length; itr++)
{
string[] fdParams = lines[itr].Split(',');
//Read name and category for feature definition
string featureDefNameToSet = fdParams[0];
string type = fdParams[1];
//Create feature definition for points category
if (type == "PointObjectSettings" && featureDefNameToSet != null)
{
var os = cmm.AddObjectSettings(featureDefNameToSet, typeof(Bentley.CifNET.GeometryModel.ContentManagement.PointObjectSettings), null);
if (os == null) continue; ;
objectSpace.PersistChanges(cmm);
}
//Create feature definition for alignments category
else if (type == "AlignmentObjectSettings" && featureDefNameToSet != null)
{
var os = cmm.AddObjectSettings(featureDefNameToSet, typeof(Bentley.CifNET.GeometryModel.ContentManagement.AlignmentObjectSettings), null);
if (os == null) continue; ;
objectSpace.PersistChanges(cmm);
}
}
return;
}
Output